package com.vehicle.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vehicle.bean.DataGridView;
import com.vehicle.bean.FeesRecordVo;
import com.vehicle.mapper.FeesRecordMapper;
import com.vehicle.pojo.FeesRecord;
import com.vehicle.service.FeesRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class FeesRecordServiceImpl implements FeesRecordService {
    @Autowired
    private FeesRecordMapper feesRecordMapper;
    @Override
    public DataGridView findAllFeesRecord(FeesRecord feesRecord) {
        Page page = PageHelper.startPage(feesRecord.getPage(),feesRecord.getLimit());
        DataGridView dataGridView = new DataGridView();
        List<FeesRecord> feesRecords= null;
        try {
            feesRecords = feesRecordMapper.selectAllFeesRecord(feesRecord);
            dataGridView.setCount(page.getTotal());
            dataGridView.setData(feesRecords);
        } catch (Exception e) {
            dataGridView.setCount(page.getTotal());
            dataGridView.setData(feesRecords);

        }
        return dataGridView;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteFeesRecordByFeesId(int feesid) {
        this.feesRecordMapper.updateStatusByFeesId(feesid);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteBatchFeesRecordByFeesIds(Integer[] feesIds) {
        for (int feesid:feesIds){
            feesRecordMapper.updateStatusByFeesId(feesid);
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addFeesRecord(FeesRecord feesRecord) {
        feesRecord.setStatus(1);
        feesRecordMapper.addFeesRecord(feesRecord);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateFeesRecord(FeesRecord feesRecord) {
        feesRecordMapper.updateFeesRecord(feesRecord);
    }
}
